<template>
  <div class="tab">
    <el-tabs v-model="activeName" type="card">
      <el-tab-pane label="充值卡操作" name="refilCard">
        <RefilCard />
      </el-tab-pane>
      <el-tab-pane label="充值卡明细" name="refilCardDetail">
        <refil-card-detail :tree-data="treeData" :info-data="infoData" :deal-map="dealMap" />
      </el-tab-pane>
      <el-tab-pane label="充值审核" name="topUpCheck">
        <top-up-check :tree-data="treeData" />
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
  import RefilCard from './components/RefilCard'
  import RefilCardDetail from './components/RefilCardDetail'
  import TopUpCheck from './components/TopUpCheck'
  import { topUpAdministrationDetail, queryMap } from '@/api'
  import getTreeData from '@/utils/jsonTree'
  import { mergeAsyncFunc } from '@/utils/mergeAsyncFunc'
  import { mapGetters } from 'vuex'
  export default {
    name: 'rechargeManage',
    components: {
      RefilCard,
      RefilCardDetail,
      TopUpCheck
    },
    data() {
      return {
        activeName: 'refilCard',
        treeData: [],
        infoData: {},
        dealMap: [] // 交易类型
      }
    },
    computed: {
      ...mapGetters([
        'orgList'
      ])
    },
    async created() {
      await Promise.all([this.getCradInfo(), this.getTreeData(), this.queryOptionsMap()])
    },
    methods: {
      // 充值卡明细
      async getCradInfo() {
        const { data } = await topUpAdministrationDetail()
        // 累计充值金额(含赠送): 累计充值金额 + 累计赠送金额
        data.totalCardAndSendMoney = (data.totalCardMoney * 1) + (data.totalSendMoney * 1)
        // 剩余充值金额（含赠送）：累计充值金额 - 累计消费金额；
        data.cashAndSendMoney = (data.totalCardAndSendMoney * 1) - (data.totalPayMoney * 1)
        this.infoData = data
      },
      // 获取所属机构数据
      async getTreeData() {
        const data = this.orgList.map(item => ({
          label: item.name,
          ...item
        }))
        this.treeData = getTreeData(data)
      },
      // 查询枚举
      async queryOptionsMap() {
        const [res1] = await Promise.all([mergeAsyncFunc(queryMap, { enumName: 'AccCsmcardRecordOptFlag' })])
        var del = [4, 6, 7, 8, 9, 10, 11, 12, 15]
        var list = []
        if (res1.data) {
          res1.data.forEach(l => {
            var flag = del.find(n => l.value === n)
            if (!flag) {
              list.push(l)
            }
          })
        }
        console.log('list......', list)
        this.dealMap = list // 交易类型
      }
    }
  }
</script>

<style lang="scss" scoped>
.tab {
  width: 100%;
  height: 100%;
  overflow: auto;
}
</style>
